package 拦截器的使用.main.java.com.itheima.config;

import com.itheima.controller.interceptor.ProjectInterceptor;
import com.itheima.controller.interceptor.ProjectInterceptor3;
import org.omg.PortableInterceptor.Interceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

@Configuration
public class SpringMvcSupport extends WebMvcConfigurationSupport {

    @Autowired
    private ProjectInterceptor3 interceptor;
    /**
     * 配置静态资源的过滤器
     * @param registry
     */
    @Override
    protected void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/pages/**").addResourceLocations("/pages/");
    }

    /**
     * 配置拦截器:定义拦截路径
     * @param registry
     */
    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        //这里需要传入Interceptors拦截器对象
        //表示当访问books的时候触发拦截器
        registry.addInterceptor(interceptor).addPathPatterns("/books","/books/*");
    }
}
